package com.nl.controller.web.controller;

import com.alibaba.fastjson.JSONArray;
import com.github.pagehelper.PageInfo;

import com.nl.controller.common.model.Response;
import com.nl.controller.common.util.AdcFunction;
import com.nl.controller.common.util.ResponseUtil;
import com.nl.controller.web.bean.ReportMonth;

import com.nl.controller.web.service.SmsCountMonthService;
import com.nl.controller.web.util.ExcelUtil;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import java.util.LinkedHashMap;
import java.util.Map;

@RequestMapping("smsCountMonth")
@Slf4j
@RestController
public class SmsCountMonthController {
    @Autowired
    private SmsCountMonthService smsCountMonthService;

    @ApiOperation(value = "报账统计和年度统计", notes = "报账统计和年度统计")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "页码", required = true, dataType = "String"),
            @ApiImplicitParam(name = "limit", value = "每页数量", required = true, dataType = "String"),
            @ApiImplicitParam(name = "year", value = "年份", required = false, dataType = "String"),
    })
    @PostMapping("find")
    public Response countMonth(
            @RequestParam(value = "page", required = true) int page,
            @RequestParam(value = "limit", required = true) int limit,
            @RequestParam(value = "year", required = false) String year
    ) {
        PageInfo<ReportMonth> pageInfo;
        pageInfo = smsCountMonthService.findSmsCount(page, limit, year);
        log.info("报账统计：{}", year);
        log.debug("年度统计：{}", pageInfo.getList().toString());
        return ResponseUtil.sucess(pageInfo.getList(), pageInfo.getTotal());
    }

    @ApiOperation(value = "报账导出", notes = "导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份", required = false, dataType = "String"),
    })
    @GetMapping("export")
    public void export(
            HttpServletRequest request,
            HttpServletResponse response
            ) {
        JSONArray ja =smsCountMonthService.download(null);//获取业务数据集
        Map<String, String> headMap = new LinkedHashMap<>();
        headMap.put("cityName", "地市");
        headMap.put("mgrName", "项目名称");
        headMap.put("long1", "长短信"+AdcFunction.getDate(1));
        headMap.put("normal1","正常短信"+AdcFunction.getDate(1));
        headMap.put("longSplit1","长短信拆分"+AdcFunction.getDate(1));
        headMap.put("normalCount1","正常短信统计"+AdcFunction.getDate(1));
        headMap.put("longCount1","长短信统计"+AdcFunction.getDate(1));
        headMap.put("long2", "长短信"+AdcFunction.getDate(2));
        headMap.put("normal2","正常短信"+AdcFunction.getDate(2));
        headMap.put("longSplit2","长短信拆分"+AdcFunction.getDate(2));
        headMap.put("normalCount2","正常短信统计"+AdcFunction.getDate(2));
        headMap.put("longCount2","长短信统计"+AdcFunction.getDate(2));
        headMap.put("long3", "长短信"+AdcFunction.getDate(3));
        headMap.put("normal3","正常短信"+AdcFunction.getDate(3));
        headMap.put("longSplit3","长短信拆分"+AdcFunction.getDate(3));
        headMap.put("normalCount3","正常短信统计"+AdcFunction.getDate(3));
        headMap.put("longCount3","长短信统计"+AdcFunction.getDate(3));
        headMap.put("long4", "长短信"+AdcFunction.getDate(4));
        headMap.put("normal4","正常短信"+AdcFunction.getDate(4));
        headMap.put("longSplit4","长短信拆分"+AdcFunction.getDate(4));
        headMap.put("normalCount4","正常短信统计"+AdcFunction.getDate(4));
        headMap.put("longCount4","长短信统计"+AdcFunction.getDate(4));
        headMap.put("long5", "长短信"+AdcFunction.getDate(5));
        headMap.put("normal5","正常短信"+AdcFunction.getDate(5));
        headMap.put("longSplit5","长短信拆分"+AdcFunction.getDate(5));
        headMap.put("normalCount5","正常短信统计"+AdcFunction.getDate(5));
        headMap.put("longCount5","长短信统计"+AdcFunction.getDate(5));
        headMap.put("long6", "长短信"+AdcFunction.getDate(6));
        headMap.put("normal6","正常短信"+AdcFunction.getDate(6));
        headMap.put("longSplit6","长短信拆分"+AdcFunction.getDate(6));
        headMap.put("normalCount6","正常短信统计"+AdcFunction.getDate(6));
        headMap.put("longCount6","长短信统计"+AdcFunction.getDate(6));
        headMap.put("long7", "长短信"+AdcFunction.getDate(7));
        headMap.put("normal7","正常短信"+AdcFunction.getDate(7));
        headMap.put("longSplit7","长短信拆分"+AdcFunction.getDate(7));
        headMap.put("normalCount7","正常短信统计"+AdcFunction.getDate(7));
        headMap.put("longCount7","长短信统计"+AdcFunction.getDate(7));
        headMap.put("long8", "长短信"+AdcFunction.getDate(8));
        headMap.put("normal8","正常短信"+AdcFunction.getDate(8));
        headMap.put("longSplit8","长短信拆分"+AdcFunction.getDate(8));
        headMap.put("normalCount8","正常短信统计"+AdcFunction.getDate(8));
        headMap.put("longCount8","长短信统计"+AdcFunction.getDate(8));
        headMap.put("long9", "长短信"+AdcFunction.getDate(9));
        headMap.put("normal9","正常短信"+AdcFunction.getDate(9));
        headMap.put("longSplit9","长短信拆分"+AdcFunction.getDate(9));
        headMap.put("normalCount9","正常短信统计"+AdcFunction.getDate(9));
        headMap.put("longCount9","长短信统计"+AdcFunction.getDate(9));
        headMap.put("long10", "长短信"+AdcFunction.getDate(10));
        headMap.put("normal10","正常短信"+AdcFunction.getDate(10));
        headMap.put("longSplit10","长短信拆分"+AdcFunction.getDate(10));
        headMap.put("normalCount10","正常短信统计"+AdcFunction.getDate(10));
        headMap.put("longCount10","长短信统计"+AdcFunction.getDate(10));
        headMap.put("long11", "长短信"+AdcFunction.getDate(11));
        headMap.put("normal11","正常短信"+AdcFunction.getDate(11));
        headMap.put("longSplit11","长短信拆分"+AdcFunction.getDate(11));
        headMap.put("normalCount11","正常短信统计"+AdcFunction.getDate(11));
        headMap.put("longCount11","长短信统计"+AdcFunction.getDate(11));
        headMap.put("long12", "长短信"+AdcFunction.getDate(12));
        headMap.put("normal12","正常短信"+AdcFunction.getDate(12));
        headMap.put("longSplit12","长短信拆分"+AdcFunction.getDate(12));
        headMap.put("normalCount12","正常短信统计"+AdcFunction.getDate(12));
        headMap.put("longCount12","长短信统计"+AdcFunction.getDate(12));
        String title = "报账统计";
        ExcelUtil.downloadExcelFile(title, headMap, ja, response,request);
        log.debug("导出的数据{}",ja.size());
    }

    @ApiOperation(value = "年度导出", notes = "导出")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "year", value = "年份", required = false, dataType = "String"),
    })
    @GetMapping("exportYear")
    public void export(
            @RequestParam(value = "year", required = false) String year,
            HttpServletRequest request,
            HttpServletResponse response
    ) {
        JSONArray ja =smsCountMonthService.download(year);//获取业务数据集
        Map<String, String> headMap = new LinkedHashMap<>();
        headMap.put("cityName", "地市");
        headMap.put("mgrName", "项目名称");
        headMap.put("long1", "1月份长短信");
        headMap.put("normal1","1月份正常短信");
        headMap.put("longSplit1","1月份长短信拆分");
        headMap.put("normalCount1","1月份正常短信统计");
        headMap.put("longCount1","1月份长短信统计");
        headMap.put("long2", "2月份长短信");
        headMap.put("normal2","2月份正常短信");
        headMap.put("longSplit2","2月份长短信拆分");
        headMap.put("normalCount2","2月份正常短信统计");
        headMap.put("longCount2","2月份长短信统计");
        headMap.put("long3", "3月份长短信");
        headMap.put("normal3","3月份正常短信");
        headMap.put("longSplit3","3月份长短信拆分");
        headMap.put("normalCount3","3月份正常短信统计");
        headMap.put("longCount3","3月份长短信统计");
        headMap.put("long4", "4月份长短信");
        headMap.put("normal4","4月份正常短信");
        headMap.put("longSplit4","4月份长短信拆分");
        headMap.put("normalCount4","4月份正常短信统计");
        headMap.put("longCount4","4月份长短信统计");
        headMap.put("long5", "5月份长短信");
        headMap.put("normal5","5月份正常短信");
        headMap.put("longSplit5","5月份长短信拆分");
        headMap.put("normalCount5","5月份正常短信统计");
        headMap.put("longCount5","5月份长短信统计");
        headMap.put("long6", "6月份长短信");
        headMap.put("normal6","6月份正常短信");
        headMap.put("longSplit6","6月份长短信拆分");
        headMap.put("normalCount6","6月份正常短信统计");
        headMap.put("longCount6","6月份长短信统计");
        headMap.put("long7", "7月份长短信");
        headMap.put("normal7","7月份正常短信");
        headMap.put("longSplit7","7月份长短信拆分");
        headMap.put("normalCount7","7月份正常短信统计");
        headMap.put("longCount7","7月份长短信统计");
        headMap.put("long8", "8月份长短信");
        headMap.put("normal8","8月份正常短信");
        headMap.put("longSplit8","8月份长短信拆分");
        headMap.put("normalCount8","8月份正常短信统计");
        headMap.put("longCount8","8月份长短信统计");
        headMap.put("long9", "9月份长短信");
        headMap.put("normal9","9月份正常短信");
        headMap.put("longSplit9","9月份长短信拆分");
        headMap.put("normalCount9","9月份正常短信统计");
        headMap.put("longCount9","9月份长短信统计");
        headMap.put("long10", "10月份长短信");
        headMap.put("normal10","10月份正常短信");
        headMap.put("longSplit10","10月份长短信拆分");
        headMap.put("normalCount10","10月份正常短信统计");
        headMap.put("longCount10","10月份长短信统计");
        headMap.put("long11", "11月份长短信");
        headMap.put("normal11","11月份正常短信");
        headMap.put("longSplit1","1月份长短信拆分");
        headMap.put("normalCount1","1月份正常短信统计");
        headMap.put("longCount1","1月份长短信统计");
        headMap.put("long12", "12月份长短信");
        headMap.put("normal12","12月份正常短信");
        headMap.put("longSplit12","12月份长短信拆分");
        headMap.put("normalCount12","12月份正常短信统计");
        headMap.put("longCount12","12月份长短信统计");
        String title = "年度统计";
        ExcelUtil.downloadExcelFile(title, headMap, ja, response,request);
        log.debug("导出的数据{}",ja.size());
    }
}

